<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
	<head>
		<meta charset="UTF-8">
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<title>网站后台管理模版</title>
		<link rel="stylesheet" type="text/css" href="../../static/admin/layui/css/layui.css" />
		<link rel="stylesheet" type="text/css" href="../../static/admin/css/admin.css" />
	</head>
	<body>
		<div class="wrap-container">
				<form class="layui-form" style="width: 90%;padding-top: 20px;">

                    <div class="layui-form-item">
                        <label class="layui-form-label">Id：</label>
                        <div class="layui-input-block">
                            <input type="text" name="label" required lay-verify="required" placeholder="请输入Id" autocomplete="off" class="layui-input accountId" readonly value="${sessionScope.accountMap.accountId}">
                        </div>
                    </div>
					<div class="layui-form-item">
						<label class="layui-form-label">部门：</label>
						<div class="layui-input-block">
							<input type="text" name="label" required lay-verify="required" placeholder="请输入部门" autocomplete="off" class="layui-input deptName">
						</div>
					</div>
					<div class="layui-form-item">
						<label class="layui-form-label">真实姓名：</label>
						<div class="layui-input-block">
							<input type="text" name="label" required lay-verify="required" placeholder="请输入真实姓名" autocomplete="off" class="layui-input realName"  >
						</div>
					</div>
					<div class="layui-form-item">
						<label class="layui-form-label">用户名：</label>
						<div class="layui-input-block">
							<input type="text" name="label" required lay-verify="required" placeholder="请输入用户名" autocomplete="off" class="layui-input accountName"  >
						</div>
					</div>
					<div class="layui-form-item">
						<label class="layui-form-label">角色：</label>
						<div class="layui-input-block">
							<input type="text" name="label" required lay-verify="required" placeholder="请输入角色" autocomplete="off" class="layui-input roleName"  >
						</div>
					</div>
					<div class="layui-form-item">
						<label class="layui-form-label">电话：</label>
						<div class="layui-input-block">
							<input type="text" name="label" required lay-verify="required" placeholder="请输入电话" autocomplete="off" class="layui-input accountTel"  >
						</div>
					</div>
					<div class="layui-form-item">
						<label class="layui-form-label">工资：</label>
						<div class="layui-input-block">
							<input type="text" name="label" required lay-verify="required" placeholder="请输入工资" autocomplete="off" class="layui-input salary"  >
						</div>
					</div>
					

					<div class="layui-form-item">
						<div class="layui-input-block">
							<button class="layui-btn layui-btn-normal updateBtn" lay-submit lay-filter="formDemo" type="button">立即提交</button>
							<button type="reset" class="layui-btn layui-btn-primary" type="button">重置</button>
						</div>
					</div>
				</form>
		</div>

		<script src="../../static/admin/layui/layui.js" type="text/javascript" charset="utf-8"></script>
		<script src="https://cdn.staticfile.org/jquery/2.0.0/jquery.min.js"></script>
		<script>


			if ("${param.accountId}" != null ){
				//获得url后面附带的参数
				var n = "${param.accountId}";
				var accountId = n.slice(0,n.length-13);

			}


			$(document).ready(function(){
                //渲染对应的部门信息
				updatePositionAjax(accountId);
			})
			function updatePositionAjax(accountId){
				$.ajax({
					async:true,
					url:"${pageContext.request.contextPath}/account/getAccountById",
					type:"GET",
					data:{accountId:accountId,
						},
					dataType:"json",
					success:function(result,status,xhr){
                    //将获得的信息返回到数据库
						$(".accountId").val(result.accountId);
                            $(".deptName").val(result.deptName);
							$(".realName").val(result.realName);
                            $(".accountName").val(result.accountName);
						$(".roleName").val(result.roleName);
						$(".accountTel").val(result.accountTel);
						$(".salary").val(result.salary);

					},
					error:function(xhr,status,error){
						alert("异步请求失败!");
					}
				});
			}
            //提交修改的内容
            $(".updateBtn").click(function () {
				var accountId =$(".accountId").val();
                var deptName =$(".deptName").val();
                var realName = $(".realName").val();
                var accountName =$(".accountName").val();
				var roleName =$(".roleName").val();
				var accountTel = $(".accountTel").val();
				var salary =$(".salary").val();

                $.ajax({
                    async:true,
                    url:"${pageContext.request.contextPath}/account/updateAccountInfo",
                    type:"post",
                    data:{
						accountId:accountId,
						deptName:deptName,
						realName:realName,
						accountName:accountName,
						roleName:roleName,
						accountTel:accountTel,
						salary:salary

                    },
                    dataType:"json",
                    success:function(result,status,xhr){
						if(result == "1"){
							alert("修改成功");
						}else {
							alert("修改失败");
						}

                    },
                    error:function(xhr,status,error){
                        alert("异步请求失败!");
                    }
                });

            })

			$(".layui-btn-primary").click(function () {
				updatePositionAjax();
			});

		</script>
	</body>

</html>